#include "menuvalue.h"

CMenuValue::CMenuValue(float fX, float fY)
    : CMenu(fX, fY)
{
}


CMenuValue::~CMenuValue()
{
    if (m_arrValueOptions.size() > 0)
    {
        for (vector<CValueOption*>::const_iterator pPos(
            m_arrValueOptions.begin()); pPos != m_arrValueOptions.end(); ++pPos)
        {
            delete *pPos;
        }
        m_arrValueOptions.clear();
    }
}

void CMenuValue::render()
{
    if (isActive())
    {
        for (vector<CValueOption*>::const_iterator pOption(
            m_arrValueOptions.begin()); pOption != m_arrValueOptions.end(); 
            ++pOption)
        {
            (*pOption)->render();
        }
        CUIText::render();
    }
}

COption* CMenuValue::getOption(int index) const
{
    return m_arrValueOptions.at(index);
}

size_t CMenuValue::getOptionCount() const
{
    return m_arrValueOptions.size();
}

CValueOption *CMenuValue::addOption(string szText, int nPositionX, 
    int nPositionY, const utils::PARAM &param)
{
    CValueOption* pOption = new CValueOption(
        m_arrValueOptions.size(), szText, param);
    pOption->setPosition(static_cast<float>(nPositionX) + getLeft(), 
        static_cast<float>(nPositionY) + getTop(), 0, 0);

    m_arrValueOptions.push_back(pOption);

    if (m_arrValueOptions.size() == 1)
    {
        pOption->setActive(true);
    }

    return pOption;
}

CValueOption *CMenuValue::addOption(string szText, int nPositionX, 
    int nPositionY)
{
    CValueOption* pOption = new CValueOption(
        m_arrValueOptions.size(), szText);
    pOption->setPosition(static_cast<float>(nPositionX) + getLeft(), 
         static_cast<float>(nPositionY) + getTop(), 0, 0);

    m_arrValueOptions.push_back(pOption);

    if (m_arrValueOptions.size() == 1)
    {
        pOption->setActive(true);
    }

    return pOption;
}